import 'package:flutter/material.dart';

class Flutter_AnimatedOpacity_Page extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return Flutter_AnimatedOpacity_State();
  }
}

class Flutter_AnimatedOpacity_State
    extends State<Flutter_AnimatedOpacity_Page> {
  var visible = true;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
            child: AnimatedOpacity(
              opacity: visible ? 1.0 : 0.0,
              duration: Duration(milliseconds: 2000),
              child: Container(
                width: 200.0,
                height: 200.0,
                color: Colors.black,
              ),
            )
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            setState(() {
              visible = !visible;
            });
          },
          child: Icon(Icons.add),
        ),
      ),
    );
  }
}

/**
 * 实现渐变效果
 * const AnimatedOpacity({
    Key key,
    this.child,
    @required this.opacity,//透明度
    Curve curve = Curves.linear,
    @required Duration duration,//时间间隔
    })
 */